<?php



if ($_POST[date]=='')
{

    $_POST[date]=$date;
}
if ($_POST[lognumber]=='')
{

    $_POST[lognumber]='%';
}
echo '<center><h1>Stats</h1>';
echo '<form method="Post" Action=index.php?p=stats>';
echo '<p>';
echo 'Date : <input type="text" name="date" size="6" value="'.$_POST[date].'" /> ';
#echo 'Log Number  : <input type="text" name="lognumber" size="6" value="'.$_POST[lognumber].'" /> ';
echo ' <input type="submit" value="Filter" name="Filter" /></form><p><b>Open Jobs<br>';
require 'Common/dashboard2.php';
echo '<p><table><tr class="noborder"><td class="noborder"><table>
<tr bgcolor="#64Bfff"><td><b>Total</td><td><b>Today</td><td><b>Yesterday</td><td><b>MTD</td><td><b>Last Month</td><td><b>YTD</td></tr>
<tr><td>Job created</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$yesterday'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$mtd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$ytd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';

echo '<tr><td>Jobs closed</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$yesterday'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$mtd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$ytd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';

echo '<tr bgcolor="#64Bfff"><td><b>Created</td>';
$result = mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($result))
{

echo '<tr><td>'.$row[Name].'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND operator LIKE '$row[Name]' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$yesterday'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$mtd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$ytd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td></tr>';
}
echo '<td>Public</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$yesterday'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$mtd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$ytd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';



echo '<tr bgcolor="#64Bfff"><td><b>Closed</td>';
$result = mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($result))
{

echo '<tr><td>'.$row[Name].'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$yesterday'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$mtd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$ytd'  ORDER BY `key` ");
echo '<td>', mysql_affected_rows() ,'</td></tr>';
}


echo'</tr></table></td>';
echo '<td valign="top" class="noborder"><table class="noborder"><tr class="noborder"><td class="noborder"><table class="noborder"><tr class="noborder" bgcolor="#64Bfff"><td>Operator</td><td>Minutes worked</td></tr>';
$query=mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($query))
{
echo '<tr><td>'.$row[Name].'</td>';
$query1=mysql_query("SELECT * FROM tblEvents WHERE Date='$_POST[date]' AND Operator='$row[Name]'");
while($row = mysql_fetch_array($query1))
{
$mins=$mins+$row[TimeS];
}
echo '<td>'.$mins.'</td></tr>';
$mins=0;
}

echo '</table></td></tr>


    <tr class="noborder"><td class="noborder">';
    echo '<table cellpadding="5" class="noborder">
    <tr class="noborder"><td>Current jobs</td>';
    mysql_query("Select * FROM tbljobs");
    echo '<td>', mysql_affected_rows() ,'</td></tr>';
    echo '<tr class="noborder"><td>Archived jobs</td>';
    mysql_query("Select * FROM tbljobsarchive");
    echo '<td>', mysql_affected_rows() ,'</td></tr>';

    echo '<tr class="noborder"><td>Current solutions</td>';
    mysql_query("Select * FROM tblsolutions");
    echo '<td>', mysql_affected_rows() ,'</td></tr>';
    echo '<tr class="noborder"><td>Archived solutions</td>';
    mysql_query("Select * FROM tblsolutionsarchive");
    echo '<td>', mysql_affected_rows() ,'</td></tr>';




    echo '</table></td></table></td></tr></table>';

echo '<p>All Open <table width="500"><tr bgcolor="#64Bfff"><td></td><td>08:00</td><td>09:00</td><td>10:00</td><td>11:00</td><td>12:00</td><td>13:00</td><td>14:00</td><td>15:00</td><td>16:00</td><td>17:00</td><td>18:00</td></tr>';
echo '<tr><td>Today</td>';
$hour='8';

while($hour<19)
{
if($hour<10)
{
$time1='0'.$hour.':00';
}
else
{
    $time1=$hour.':00';
}
$query=mysql_query("SELECT * FROM tblhstats WHERE Date='$date' AND Time='$time1'");
if(mysql_affected_rows()>0)
{
while($row = mysql_fetch_array($query))
{
echo '<td>'.$row['Allopen'].'</td>';
}

}
else
{
echo '<td>0</td>';

}
$hour=$hour+1;
}

echo '<tr><td>Yesterday</td>';
$hour='8';

while($hour<19)
{
if($hour<10)
{
$time1='0'.$hour.':00';
}
else
{
    $time1=$hour.':00';
}
$query=mysql_query("SELECT * FROM tblhstats WHERE Date='$yesterday' AND Time='$time1'");
if(mysql_affected_rows()>0)
{
while($row = mysql_fetch_array($query))
{
echo '<td>'.$row['Allopen'].'</td>';
}

}
else
{
echo '<td>0</td>';

}
$hour=$hour+1;
}

echo '<tr><td>Custom</td>';
$hour='8';

while($hour<19)
{
if($hour<10)
{
$time1='0'.$hour.':00';
}
else
{
    $time1=$hour.':00';
}
$query=mysql_query("SELECT * FROM tblhstats WHERE Date='$_POST[date]' AND Time='$time1'");
if(mysql_affected_rows()>0)
{
while($row = mysql_fetch_array($query))
{
echo '<td>'.$row['Allopen'].'</td>';
}

}
else
{
echo '<td>0</td>';

}
$hour=$hour+1;
}


echo '</table>';


?>
